<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>个人中心</title>
    <link rel="icon" href="../images/小图标.jpg"> 
    <link rel="stylesheet" href="../css/header.css">
    <link rel="stylesheet" href="../css/personal.css">
    <link rel="stylesheet" href="../css/footer.css">
    <script src="https://cdn.bootcdn.net/ajax/libs/jquery/3.6.1/jquery.js"></script>
    <script>
        $(function(){
            let userId = JSON.parse(localStorage.getItem('loginUser'))._id
            $.ajax({
                url:'http://localhost:3000/api/getUserInfoById',
                type:'get',
                data:{userId},
                success:function(res){
                    if(res.message == 'ok'){
                        $('.userName'),html('姓名：'+ res.user.name)
                        $('.piched'),attr('src'`http://localhost:3000/${res.user.headpic}` )
                        $('.sex'),html(`性别： ${res.user.sex?'男':'女'}`)
                        $('.mobile'),html(`电话： ${res.user.mobile}`)
                        $('.birth'),html(`生日：${res.user.birth}`)
                        $('.address').html(`地址：${res.user.birth}`)
                    }else{
                        alert('个人信息获取失败！')
                    }
                }
            })
        })

        function changePwd(){
            let userId = JSON.parse(localStorage.getItem('loginUser'))._id
            let userOldPwd = $('.oldPwd').val()
            let userNewPwd = $('.newPwd').val()
            $.ajax({
                url:'http://localhost:3000/api/changePwd',
                type:'post',
                data:{userId,userOldPwd,userNewPwd},
                success:function(res){
                    if(reg.message == 'ok'){
                        alert('修改密码成功！')
                    }else{
                        alert('修改密码失败！')
                    }
                }
            })
        }
        function selectFile(){
            $('#headPic').click()
        }
        function uploadHeadPic(file){
            let userId = JSON.parse(localStorage.getItem('loginUser'))._id
            let fd =new FormData()
            fd.append('file',file.files[0])
            fd.append('userId',userId)
            $.ajax({
                url:'http://localhost:3000/api/uploadHeadPic',
                type:'post',
                data:fd,
                processData:false,
                contentType:false,
                data:fd,
                success:function(res){
                    if(res.message == 'ok'){
                        let headpic = `http://localhost:3000/upload/${res.data}`
                        $('.piched').attr('src',headpic)
                    }else{
                        alert(res.message)
                    }
                }
            })
        }
    </script>
    
    
</head>
<body>
    <header>
        <div>
            <a href="../html/index.html"><img src="../images/login.png" alt=""></a>
            <form action="">
                <input type="text" value=""class="text">
                <input type="button" value="搜索" class="mybutton">
                </form>
            <ul class="tu">
                <li><span><a href="../html/index.html">首页</a></span></li>
                <li><span>蛋糕</span></li>
                <li><span>全国配</span></li>
                <li><span>合作专区</span>
                    <ul class="tul">
                        <li>银行活动</li>
                        <li>企业采购</li>
                        <li>大客户区</li>
                    </ul>
                </li>
                <li><span>立即兑换</span></li>
            </ul>
            <a href="../html/shoppingCar.html" class="d3"><i></i>购物车</a>
        </div>
    </header>
    <div id="contentCon">
        <div class="left">
            <img src="" alt="" class="piched" width="200px" height="200px">  
            <input type="file" name="" id="headPic" style="display:none" enctype="multipart/form-data"
            onchange="uploadHeadPic(this)">
            <input type="button" value="修改图像" onclick="selectFile()">
            <h3 class="userName">用户账号</h3>
           
            <span></span>
            <ul>
                <li><a href="#">个人信息</a></li>
                <li><a href="order.html">我的订单</a></li>
                <!-- <li><a href="#">我的钱包</a></li> -->
                <li><a href="#">优惠特权</a></li>
                <li><a href="address.html">地址管理</a></li>
                <li><a href="#">账号设置</a></li>
                <li><a href="#">我的足迹</a></li>
                <li><a href="Service.html">帮助中心</a></li>
            </ul>
        </div>
        <div class="right">
            <ul>
                <p>基本资料</p>
                <span></span>
            </ul>
            <div class="info">
                    <h3 class="userName">用户账号</h3>
                    <p class="sex">性&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;别</p>
                    <p class="birth">生&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;日</p>
                    <p class="address">地&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;址</p>
                    <p class="phone">手机号码</p>
            </div>
            <span></span>
            <div class="changePwd">
                原密码：<input type="password" name="oldPwd" id="" class="oldPwd">
                新密码：<input type="button" name="newPwd" id="" class="newPwd">
                <input type="button" value="修改密码" onclick="changePwd()">
            </div>
        </div>
    </div>
    <footer>
        <div class="footer">
            <img class="footer-logo" src="../images/logo.png" height="23" width="200" alt="">
            <div class="footer-nav">
                <a>诺心公告</a>
                <span>|</span>
                <a>关于诺心</a>
                <span>|</span>
                <a>客服服务</a>
                <span>|</span>
                <a>生产经营资质</a>
                <span>|</span>
                <a>公告专区</a>
            </div>
            <div class="footer-icon">
                <a href="http://weibo.com/21cake" target="_blank">
                    <img src="../images/footericon-01.png">
                </a>
                <a class="footer-weixin">
                    <div class="footer-erweima footer-weixin-erweima">
                        <img src="../images/erweima.png">
                    </div>
                    <img src="../images/footericon-02.png">
                </a>
                <a class="footer-app">
                    <div class="footer-erweima footer-app-erweima">
                        <img src="../images/erweima.png">
                    </div>
                    APP
                </a>
            </div>

            <div class="footer-text">
                <span>订购专线：4001-578-578（服务时间 09:00–21:00）</span>
                <span>客服电话：021-23099721（全国） | services@lecake.com（邮箱）</span>
                <span>杭州/广州：提前5小时预订；北京：提前6小时预订；上海：提前5.5-6小时预订；天津/苏州/无锡/深圳：提前8小时预订（部分偏远地区除外，当日22点以后订单，于次日8点开始审核） </span>
                <span>当日蛋糕配送截止下单时间：北京：16:50；上海：16:30；杭州/广州：13:50；天津：10:30；苏州/无锡/深圳：11:00</span>
                <span>网站注册公司名称: 诺心食品（上海）有限公司  地址: 上海市徐汇区虹漕路68号锦和中心7楼A、C单元 </span>
            </div>
            <div class="footer-copyright">
                <span>Copyright© 诺心leCake蛋糕官网商城 2010-2022, 版权所有 <a style="color: #9a9a9a" target="_blank" href="https://beian.miit.gov.cn/#/Integrated/index">沪ICP备10211730号-2</a></span>
            </div>
        </div>
    </footer>
</body>
</html>